package app.foodnote;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import app.foodnote.db.FoodNotesDataSource;

public class DetailActivity extends Activity {
	 private FoodNotesDataSource datasource;
	 String detailId = null;
	 String foodSearch = null;
	 
	 private TextView detailName;
	 private TextView detailAddress;
	 private TextView detailCity;
	 private TextView detailPhone;
	 private TextView detailOntherNote;
	 private TextView detailLocation;
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setTitle("Chi Tiết Món Ăn");
	        setContentView(R.layout.detail);
	        detailName = (TextView) findViewById(R.id.detail_name);
	        detailAddress = (TextView) findViewById(R.id.detail_address);
	        detailCity = (TextView) findViewById(R.id.detail_city);
	        detailPhone = (TextView) findViewById(R.id.detail_phone);
	        detailOntherNote = (TextView) findViewById(R.id.detail_note);
	        detailLocation = (TextView) findViewById(R.id.detail_location);
	        datasource = new FoodNotesDataSource(this);
	        
	        detailId = getIntent().getStringExtra(FoodPlaces.ID_EXTRA);
	        loadFood(detailId);
	 }
	private void loadFood(String Id) {
		datasource.openToRead();
		Cursor c = datasource.getFoodNoteById(Id);
		c.moveToFirst();
		detailName.setText(datasource.getName(c));
		detailAddress.setText(datasource.getAddress(c));
		detailPhone.setText(datasource.getPhoneNumber(c));
		detailCity.setText(datasource.getCity(c));
		detailOntherNote.setText(datasource.getOtherNote(c));
		detailLocation.setText(String.valueOf(datasource.getLongitude(c) + ", "
				+ String.valueOf(datasource.getLatitude(c))
				));
		c.close();
		datasource.close();
	}
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.form_detail, menu);
		return true;
	}
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == R.id.detail){
			
			Intent back = new Intent(DetailActivity.this, FoodPlaces.class);
			startActivity(back);
		}
		return super.onOptionsItemSelected(item);
	}
}
